package com.liu.npc.controller;


import com.liu.common.entity.R;
import com.liu.npc.entity.base.NpcTriggerConditionsInfo;
import com.liu.npc.service.INpcTriggerConditionsInfoService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * NPC触发条件信息表 前端控制器
 * </p>
 *
 * @author LiuChengLong
 * @since 2022-11-06
 */
@RestController
@RequestMapping("/npc/npcTriggerConditionsInfo")
public class NpcTriggerConditionsInfoController {

    @Resource
    private INpcTriggerConditionsInfoService npcTriggerConditionsInfoService;

    /**
     * 新增NPC触发条件
     * @param npcTriggerConditionsInfo NPC触发条件
     * @return
     */
    @PostMapping("/addTriggerConditions")
    public R<T> addTriggerConditions(@RequestBody NpcTriggerConditionsInfo npcTriggerConditionsInfo){
        boolean save = npcTriggerConditionsInfoService.save(npcTriggerConditionsInfo);
        if (save){
            return R.success();
        }
        return R.failed();
    }

    /**
     * 更新NPC触发条件
     * @param npcTriggerConditionsInfo NPC触发条件
     * @return
     */
    @PostMapping("/updateTriggerConditions")
    public R<T> updateTriggerConditions(@RequestBody NpcTriggerConditionsInfo npcTriggerConditionsInfo){
        boolean update = npcTriggerConditionsInfoService.updateById(npcTriggerConditionsInfo);
        if (update){
            return R.success();
        }
        return R.failed();
    }

    /**
     * 获取所有NPC触发条件
     * @return NPC触发条件
     */
    @GetMapping("/getAllTriggerConditions")
    public R<List<NpcTriggerConditionsInfo>> updateTriggerConditions(){
        List<NpcTriggerConditionsInfo> resultList = npcTriggerConditionsInfoService.list();
        return R.success(resultList);
    }

}

